package com.mvc.dao.imp;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.mvc.dao.UserDao;
import com.mvc.vo.User;

@Repository
public class UserDaoImpl extends HibernateDaoSupport implements UserDao {
	@Resource
	public void setMySessionFactory(SessionFactory sessionFactory){
		this.setSessionFactory(sessionFactory);
	}
	
	@SuppressWarnings("unchecked")
	public List<User> list() {
		List<User> list = null;
		try {
			list = this.getHibernateTemplate().find("from User");
		} catch (DataAccessException e) {
			e.printStackTrace();
		}
		return list;
	}

	public User getUser(String id) {
		User u = null;
		u = this.getHibernateTemplate().get(User.class, id);
		return u;
	}

	public void update(User user) {
		this.getHibernateTemplate().update(user);
	}

	public void delete(User user) {
		this.getHibernateTemplate().delete(user);
	}

	public void insert(User user) {
		this.getHibernateTemplate().save(user);
	}
	
}
